
package com.work.util;

import java.util.List;

import com.work.db.*;
import com.work.db.entity.*;

public class EntityUtils<T> {

	private GenericDaoImpl<T, Long> daoImpl = null;

	@SuppressWarnings("unchecked")
	public EntityUtils(Class<T> type) {
		if (type.equals(WorkDay.class)) {
			daoImpl = (GenericDaoImpl<T, Long>) DaoFactory.instance().getWorkDayDao();
		} else if (type.equals(Presents.class)) {
			daoImpl = (GenericDaoImpl<T, Long>) DaoFactory.instance().getPresentsDao();
		} else if (type.equals(LeaveOfAbsence.class)) {
			daoImpl = (GenericDaoImpl<T, Long>) DaoFactory.instance().getLeaveDao();
		} else if (type.equals(Employer.class)) {
			daoImpl = (GenericDaoImpl<T, Long>) DaoFactory.instance().getEmployerDao();
		} else if (type.equals(Rate.class)) {
			daoImpl = (GenericDaoImpl<T, Long>) DaoFactory.instance().getRateDao();
		} else if (type.equals(LeavePerYear.class)) {
			daoImpl = (GenericDaoImpl<T, Long>) DaoFactory.instance().getLeavePerYearDao();
		}
	}

	public void deleteAll()
	{
		List<T> entityList = daoImpl.findAll();
		if (entityList != null) {
			daoImpl.deleteList(entityList);
		}
	}
}
